package  
{
	import org.flixel.*;
	/**
	 * ...
	 * @author morgan
	 */
	public class Particle extends FlxSprite
	{
		[Embed (source = "../data/explosion.png")] private var img_explosion:Class;
		[Embed (source = "../data/thruster.png")] private var img_thruster:Class;
		
		public static var EXPLOSION:int = 0;
		public static var THRUSTER:int = 1;
		public static var THRUSTER2:int = 2;
		
		public var life:Number = 0;
		
		public function Particle() 
		{
			super(0, 0);
		}
		
		public function spawn(type:int, x:int, y:int):void
		{
			velocity.x = 0;
			velocity.y = 0;
			_animations = new Array();
			if (type == EXPLOSION)
			{
				loadGraphic(img_explosion, true, false, 45, 45);
				addAnimation("default", [0, 1, 2, 3], 10, false);
				play("default");
				life = 0.5;
			}
			else if (type == THRUSTER)
			{
				loadGraphic(img_thruster, true, false, 40, 40);
				addAnimation("default", [1, 2, 3], 8, false);
				play("default");
				life = 0.5 + Math.random() * 0.25;
				velocity.y = 30;
			}
			else if (type == THRUSTER2)
			{
				loadGraphic(img_thruster, true, false, 40, 40);
				addAnimation("default", [2, 3], 5, false);
				play("default");
				life = 0.5 + Math.random() * 0.25;
				velocity.y = 30;
			}			
			this.x = x - width / 2;
			this.y = y - height / 2;
			exists = true;
		}
		
		override public function update():void 
		{
			life -= FlxG.elapsed;
			if (life < 0)
			{
				exists = false;
			}
			alpha = life * 2;
			super.update();
		}
		
	}

}